import { observable, configure, action, runInAction} from 'mobx'
import CardManager from '../service/CardManager'
import { pureAreaData, pureBankData } from 'src/util'

configure({enforceActions: 'observed'})

class Config {
    constructor(){
        this.init()
    }
    @observable cardList = {}
    @observable areaData = []
    @observable areaPureData = []
    @observable banks = []
    @observable banksPureData = []

    @action fetchCardList = (payload) => {
        return CardManager.fetchCardList(payload).then((res)=> {
            runInAction(()=> {
                this.cardList[payload.status] = res.data.list
            })
        })
    }

    @action addCreditCard = (payload) => {
        return CardManager.addCard(payload)
    }

    @action addPlan = (payload) => {
        return CardManager.autoCreatePlan(payload)
    }

    @action fetchArea = (payload) => {
        return CardManager.fetchProvinces(payload).then((res) => {
            runInAction(()=>{
                this.areaData = res.data
                this.areaPureData = pureAreaData(res.data)
            })
        })
    }

    @action fetchBanks = (payload) => {
        return CardManager.fetchBankList(payload).then((res) => {
            console.log('res===>>>',res)
            runInAction(()=>{
                this.banks = res.data
                this.banksPureData = pureBankData(res.data)
            })
        })
    }
    @action makeSurePlan = (payload) => {
        return CardManager.makeSurePlan(payload).then((res) => {
            return res
        })
    }
    @action authCard = (payload) => {
        return CardManager.authCard(payload).then((res) => {
            return res
        })
    }
    @action authCardComfirm = (payload) => {
        return CardManager.authCardConfirm(payload).then((res) => {
            return res
        })
    }

    @action updatePlan = (payload) => {
        return CardManager.updatePlan(payload).then((res) => {
            return res
        })
    }

    async init() {

    }
}

export default Config